#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll int
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e9
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> vec[1000010];
ll t,n,sa[1000010],rk[1000010],b[2000020];
ll lg[1000010],fa[40000040],lsh[1000010],cnt=0,f[1000010],lst[1000010];
ll pos[110],m=0,blg[1000010],p[1000010],cntt=0,mp[1000010];
char ans[1000010];
il ll id(ll x,ll dep,ll o){
	return 2*(n*dep+x-1)+o+1;
}
il ll find(ll x){
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
il void merge(ll x,ll y,ll dep){
	if(find(id(x,dep,0))==find(id(y,dep,1))) return;
	fa[find(id(x,dep,0))]=find(id(y,dep,1));
	if(!dep) return;
	merge(x,y+(1ll<<(dep-1)),dep-1);
	merge(x+(1ll<<(dep-1)),y,dep-1);
}
il void merge0(ll l1,ll r1,ll l2,ll r2){
	if(l1>r1||l2>r2) return;
	ll tmp=lg[r1-l1+1];
	merge(l1,r2-(1ll<<tmp)+1,tmp);
	merge(l2-(1ll<<tmp)+1,r1,tmp);
}
il void clr(){
	fr(i,1,n) vec[i].clear();
	fr(i,1,n) sa[i]=rk[i]=0;
	fr(i,1,cnt) lst[i]=0;
	fr(i,1,n) blg[i]=0;
	m=cnt=cntt=0;
}
int main(){
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	t=read();
	while(t--){
		n=read();
		fr(i,1,n) sa[i]=read()+1;
		fr(i,1,2*n-1) b[i]=read(); 
		bl ck=0;
		fr(i,1,n){
			if(rk[sa[i]]) ck=1;
			rk[sa[i]]=i;
		}
		fr(i,1,2*n-1) if((b[i]%2)!=(i%2)) ck=1;
		fr(i,1,n) if(b[2*i-1]>(2*min(i-1,n-i)+1)) ck=1;
		fr(i,1,n-1) if(b[2*i]>2*min(i,n-i)) ck=1;
		if(ck){
			writeln(-1);
			clr();
			continue;
		}
		fr(i,2,n) lg[i]=lg[i>>1]+1;
		fr(i,1,2*(lg[n]+1)*n) fa[i]=i;
		fr(i,1,n) fa[id(i,0,0)]=id(i,0,1);
		fr(i,1,2*n-1){
			if(i&1){
				ll x=i/2+1;
				merge0(x-b[i]/2,x-1,x+1,x+b[i]/2);
			}
			else{
				ll x=i/2;
				merge0(x-b[i]/2+1,x,x+1,x+b[i]/2);
			}
		}
		fr(i,1,n) lsh[++cnt]=f[i]=find(id(i,0,0));
		sort(lsh+1,lsh+cnt+1);
		cnt=unique(lsh+1,lsh+cnt+1)-lsh-1;
		fr(i,1,n) fa[i]=i;
		fr(i,1,n){
			f[i]=lower_bound(lsh+1,lsh+cnt+1,f[i])-lsh;
			if(lst[f[i]]){
				ll l=rk[lst[f[i]]],r=rk[i];
				if(l>r) swap(l,r);
				l=find(l);
				while(l<r){
					fa[find(l)]=find(l+1);
					l=find(l+1);
				}
			}
			lst[f[i]]=i;
		}
		fr(i,1,n-1){
			if(rk[sa[i]+1]>rk[sa[i+1]+1]) pos[++m]=i;
			if(m>=26){
				ck=1;
				break;
			}
		}
		if(ck){
			writeln(-1);
			clr();
			continue;
		}
		pos[m+1]=n;
		fr(i,1,m+1) fr(j,pos[i-1]+1,pos[i]) blg[j]=i;
		fr(i,1,n) if(blg[find(i)]!=blg[i]) ck=1;
		if(ck){
			writeln(-1);
			clr();
			continue;
		}
		fr(i,1,n) if(fa[i]==i) p[++cntt]=i;
		fr(i,1,cntt) mp[p[i]]=i;
		fr(i,1,2*n-1){
			if(i&1){
				ll l=i/2+1-b[i]/2-1,r=i/2+1+b[i]/2+1;
				if(l<1||r>n) continue;
				l=rk[l];
				r=rk[r];
				if(l>r) swap(l,r);
				if(find(l)==find(r)) ck=1;
				else vec[mp[fa[l]]].push_back(mp[fa[r]]-1);
			}
			else{
				ll l=i/2-b[i]/2,r=i/2+1+b[i]/2;
				if(l<1||r>n) continue;
				l=rk[l];
				r=rk[r];
				if(l>r) swap(l,r);
				if(find(l)==find(r)) ck=1;
				else vec[mp[fa[l]]].push_back(mp[fa[r]]-1);
			}
		}
		if(ck){
			writeln(-1);
			clr();
			continue;
		}
		char now='a';
		ll minn=inf;
		fr(i,1,cntt){
			ans[p[i]]=now;
			fr(j,0,(ll)vec[i].size()-1) minn=min(minn,vec[i][j]);
			if(i==cntt) break;
			if(minn==i||blg[p[i]]!=blg[p[i+1]]){
				now++;
				if(now>'z'){
					ck=1;
					break;
				}
				minn=inf;
			}
		}
		if(ck){
			writeln(-1);
			clr();
			continue;
		}
		fr(i,1,n) ans[i]=ans[fa[i]];
		fr(i,1,n) pc(ans[rk[i]]);
		enter;
		clr();
	}
}
